from ollama import Client
import re
import json

client = Client(
    host='http://192.168.192.171:11434',
)

# 使用模型对内容进行分块
def llm_chunk(content):
    resp = client.chat(
        model='qwen3:4b',
        messages=[
            {
                "role": "system",
                "content": "你是一个内容分块助手，你需要将我提供的内容进行分块，必须严格返回一个json格式数组！格式如下：[{'content': '内容1'},{'content': '内容2'},...]"
            },
            {
                "role": "user",
                "content": content
            },
        ]
    )

    # 获取分块内容
    content = resp['message']['content']
    # 去掉 <think> </think>
    content = content.split('</think>')[1]
    # 去除markdown格式
    content = content.replace('```json','').replace('```','')

    print(content)
    #将字符串转换成json
    content = json.loads(content)


    return content


def llm_embedding(content):
    embedResp = client.embed(model='nomic-embed-text:latest',input=content)
    return embedResp.embeddings
